package code.remote.service {

import code.remote.ResultReceivedEvent;
import code.remote.request.UserLoginRequest;
	

public class LoginService implements ILoginService {
	
	private var _fnResult: Function;
	
	public function LoginService() {
	}

	public function login(username:String, password:String, fnResult: Function): void {
		_fnResult = fnResult;
		
		const req: UserLoginRequest = new UserLoginRequest(username, password);
		req.addEventListener(ResultReceivedEvent.RESULT_RECEIVED, onResult);
		req.doSend();
	}
	
	private function onResult(event: ResultReceivedEvent): void {
		var obj: Object = event.resultEvent.result;
		const returnedUserId: int = int(event.resultEvent.result.Result.UserId);
		_fnResult(returnedUserId);
	}
	
}
}